home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / LISP Related / U. Mass AI & LISP Tools / UTILITY / MATH.lisp < prev    next >
Encoding:
Text File  |  1990-06-25  |  5.2 KB  |  105 lines  |  [TEXT/CCL ]

  1. ; (c) Copyright 1990 by University of Massachusetts. All rights reserved.
  2. ; This software was conceived, designed, and written by Dan Suthers 
  3. ; while supported by the National Science Foundation under grant number
  4. ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
  5. ; CA.  Partial support was also received from the Office of Naval Research
  6. ; under a University Research Initiative Grant, contract N00014-86-K-0764.
  7. ; Mr. Suthers created this software under his own initiative while in an 
  8. ; academic relationship with the University of Massachusetts.  The above
  9. ; copyright notice was a condition placed by University lawyers on approval
  10. ; of distribution of this software by Apple Computer, and is not meant to
  11. ; imply that this software was created in an employment or "work for hire"
  12. ; relationship between the University and Mr. Suthers.
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ; File:         MATH.lisp
  15. ; Author:       Dan Suthers
  16. ; Created:      16-Jun-88 10:32:58
  17. ; Modified:     22-Jun-90 02:04:23 (Dan Suthers)
  18. ; Language:     Common Lisp
  19. ; Package:      UTILS
  20. ;
  21. ; Description:  Math utilities: averaging, interpolation, coordinate conversion.
  22. ;
  23. ; (c) Copyright 1988, by Daniel D. Suthers
  24. ;                        Department of Computer and Information Science
  25. ;                        University of Massachusetts
  26. ;                        Amherst, Massachusetts 01003
  27. ;
  28. ; This software was conceived, designed, and written by Dan Suthers 
  29. ; while supported by the National Science Foundation under grant number
  30. ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
  31. ; CA.  Partial support was also received from the Office of Naval Research
  32. ; under a University Research Initiative Grant, contract N00014-86-K-0764.
  33. ; I wish to acknowledge the generous support of Beverly Woolf, who obtained 
  34. ; the above grants and encouraged me to pursue my own research interests in
  35. ; her lab.  This work would not have been possible without the resources and
  36. ; stimulating environment of the Computer and Information Science department.
  37. ;
  38. ; Permission to use, modify, and distribute this software is granted subject 
  39. ; to the following restrictions and understandings:
  40. ; 1. The file header, including this notice, shall be retained, and may be
  41. ;    extended to include documentation of modifications to the software.
  42. ; 2. This material is for nonprofit educational and research purposes only.
  43. ;    Users are requested, but not required, to inform Mr. Suthers of any 
  44. ;    noteworthy uses of this software.
  45. ; 3. Mr. Suthers and the University of Massachusetts make no warrantee or
  46. ;    representation that the operation of this software will be error free,
  47. ;    and are under no obligation to provide any services.
  48. ; 4. Any user of such software agrees to indemnify and hold harmless Mr.
  49. ;    Suthers and the University of Massachusetts from all claims arising 
  50. ;    out of the use or misuse of this software, or arising out of any 
  51. ;    accident, injury, or damage whatsoever, and from all costs, counsel
  52. ;    fees, and liabilities incurred in or about any such claim, action, or
  53. ;    proceeding brought thereon.
  54. ; 5. All materials and reports developed as a consequence of the use of 
  55. ;    this software shall duly acknowledge such use, in accordance with
  56. ;    the usual standards of acknowledging credit in academic research.
  57.  
  58. ;
  59. ; Status:       Done and tested.
  60. ;
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62.  
  63. (in-package :UTILS)
  64.  
  65. (export '(
  66.           degrees
  67.           exponential-average
  68.           linear-interpolation
  69.           radians
  70.           ))
  71.  
  72. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  73.  
  74. (defun EXPONENTIAL-AVERAGE (decay-rate new-value old-value)
  75.   "exponential-average <decay-rate> <new-value> <old-value>         [Function]
  76.   Computes the classic formula for an incremental exponential average:
  77.     average(0) = 0
  78.     average(t+1) = decay-rate*value(t) + (1 - decay-rate)*average(t)"
  79.   (+ (* decay-rate new-value) (* (- 1.0 decay-rate) old-value)))
  80.  
  81. (defun LINEAR-INTERPOLATION (low-x low-y val high-x high-y)
  82.   "linear-interpolation <x1> <f(x1)> <x'> <x2> <f(x2)>              [Function]
  83.   Assume you have a function where f(<x1>) = <f(x1)> and f(<x2>) = <f(x2)>.
  84.   Given an <x'> where <x1> <= <x'> <= <x2>, does linear interpolation using:
  85.       <f(x1)> + [(<x'> - <x1>) / (<x2> - <x1>)] * [<f(x2)> - <f(x1)>]
  86.   to estimate the value of f(<x'>) and returns the floating point result."
  87.   (+ (float low-y)                               ; Height of baseline 
  88.      (* (- (float high-y) (float low-y))         ; Maximum height above baseline
  89.         (/ (- (float val)    (float low-x))      ; Ratio expression of how far
  90.            (- (float high-x) (float low-x)) )))) ;  val is along base line.
  91.  
  92. (defmacro RADIANS (angle)
  93.   "radians <angle>                                                    [Macro]
  94.    Converts degrees to radians."
  95.   `(* ,angle (/ pi 180.0)))
  96.  
  97. (defmacro DEGREES (radian)
  98.   "degrees <radian>                                                   [Macro]
  99.   Converts radians to degrees."
  100.   `(* ,radian (/ 180.0 pi)))
  101.  
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103. (provide :MATH)
  104. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  105. ;;; EOF